﻿/////////////////////////////////////////////////////////////////////
//
//	Map_FVG C# Class Library.
//
//	infoDialog8
//
//	autore: Gustavo Mainardi 
//	versione: 1.0
//	data: 01/12/2015
//
//
//	Cronologia delle versioni:
//
//	Versione 1.0 01/12/2015
//		versione originale
//
//////////////////////////////////////////////////////////////////////////
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SQLite;

namespace Map_Fvg
{
    public partial class infoDialog8 : Form
    {
        public infoDialog8()
        {
            InitializeComponent();

            using (SQLiteConnection conn = SetConnection())
            {
                conn.Open();
                using (SQLiteCommand cmd = new SQLiteCommand(conn))
                {

                    string ss = "select * from area WHERE codice_area = '";
                    ss = string.Concat(ss, Simbol.selectedLinea, "'");

                    //          MessageBox.Show(ss);
                    cmd.CommandText = ss;

                    SQLiteDataReader reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            textBox1.Text = reader.GetString(0).ToString();
                            textBox2.Text = reader.GetString(1).ToString();
                            textBox4.Text = reader.GetString(3).ToString();
                            textBox3.Text = reader.GetString(5).ToString();
                            textBox5.Text = reader.GetString(6).ToString();
                            textBox6.Text = reader.GetString(4).ToString();
                            textBox7.Text = reader.GetString(2).ToString();

                        }
                    }
                }

                conn.Close();
            }

            string[] words;
            char[] delimiterChars = { ' ', ',' };

            string s1 = textBox5.Text;
            textBox5.Text = "";
            words = s1.Split(delimiterChars);
            byte b1 = byte.Parse(words[0]);
            byte b2 = byte.Parse(words[1]);
            byte b3 = byte.Parse(words[2]);
            byte b4 = byte.Parse(words[3]);
            textBox5.BackColor = Color.FromArgb(b1, b2, b3, b4);

        }

        private SQLiteConnection SetConnection()
        {
            string DataSource = "Data Source=";
            DataSource = string.Concat(DataSource, FormIniz.cartellaSimb, ";");
            SQLiteConnection conn = new SQLiteConnection(DataSource);
            return (conn);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //  conferma
            string s2 = textBox2.Text;
            if (s2.Length == 0)
            {
                MessageBox.Show("manca denominazione area");
                return;
            }

            string s3 = textBox3.Text;
            if (s3.Length == 0)
            {
                MessageBox.Show("indicare bordo");
                return;
            }

            string s4 = textBox4.Text;

            string s5 = textBox6.Text;
            string s6 = textBox7.Text;

            Color icol = textBox5.BackColor;

            string ss = icol.A.ToString();

            ss = string.Concat(ss, " ", icol.R.ToString(), " ", icol.G.ToString(), " ", icol.B.ToString());

            using (SQLiteConnection conn = SetConnection())
            {
                conn.Open();
                using (SQLiteCommand cmd = new SQLiteCommand(conn))
                {

                    ss = "update area set denom_area = '" + s2 + "', bordo = '" + s3 + "', campitura = '" + s4 + "', colore ='" + ss +
                        "' ,codice_bordo = '" + s5 + "', codice_camp = '" + s6 + "' WHERE codice_area = '";
                    ss = string.Concat(ss, Simbol.selectedLinea, "'");

                    //                                MessageBox.Show(ss);
                    cmd.CommandText = ss;

                    cmd.ExecuteNonQuery();
                }
                conn.Close();
            }
            this.Close();


            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //  annulla

            this.Close();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            ColorDialog colorDialog1 = new ColorDialog();
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox5.BackColor = colorDialog1.Color;
            }
        }


    }
}
